<?php

/*
 * This class is used for common same function.
 */

class Model_Appointment extends Model_Base {

    protected $_name = 'appointment';
    protected $_primaryKey = 'app_id';

    
    public function  fetchAppointmentData(){
        $select = $this->select()->setIntegrityCheck(false)
                ->from(array('usr' => 'appointment'));
        $result = $this->fetchAll($select);
        
        $finalArray[''] = '';
        foreach ($result as $user) {
            $finalArray[$user['appointment_id']] = $user['mem_name']." (".$user['appointment_email'].") #".$user['appointment_phone'];
        }
        return $finalArray;
    }
    
    
    public function  fetchAppointmentAllData($where = "", $limit = "", $offset = "0", $order = 'app_id', $sort = 'ASC'){
        $select = $this->select()->setIntegrityCheck(false)
                ->from(array('usr' => 'appointment'))
                ->join(array('mem' => 'members_details'), "usr.app_member_id = mem.member_id");
        if ($where != '') {
            $select->where($where);
        }
        if ($limit != "") {
            $select->limit($limit, $offset);
        }
        $select->order($order . " " . $sort);
        
       # echo $select; exit;
        
        $result = parent::fetchAll($select);
        
        if (!empty($result)) {
            return $result->toArray();
        } else {
            return array();
        }
    }
    
     public function getAppointmentCount($where) {
        
        $select = $this->select()
                ->from(array('usr' => 'appointment'), Array('cnt' => 'count(*)'))
                ->setIntegrityCheck(false)
                ->join(array('mem' => 'members_details'), "usr.app_member_id = mem.member_id");
        
        
        if ($where != '') {
            $select->where($where);
        }

        $rows = parent::fetchRow($select);
        return($rows->cnt);
    }


   
  
    
    
   
  
    /**
     * Fetch an individual entry
     *
     * @param  int|string $id
     * @return null|Zend_Db_Table_Row_Abstract
     */
    public function fetchEntryById($id) {
        $select = $this->select()
                ->from(array('lgn' => 'appointment'))
                ->where('lgn.app_id = ?', $id);
        // see reasoning in fetchEntries() as to why we return only an array
       # echo $select;exit;
        $data = $this->fetchRow($select);
        if (!empty($data)) {
            return $data->toArray();
        } else {
            return array();
        }
    }
   

}
